package com.yuting.code.service;

import org.aspectj.apache.bcel.classfile.Code;
import org.springframework.stereotype.Service;

import java.util.Random;

@Service
public class CodeService {

    final char[] codes = {
            '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
            'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',
            'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'
    };

    private final Random random = new Random();
    public String codeGenerate(int bits){
        StringBuilder stringBuilder = new StringBuilder();
        for(int i = 0; i <= bits - 1; i++){
            stringBuilder.append(codes[random.nextInt(codes.length)]);
        }
        return stringBuilder.toString();
    }



}
